﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class 号码导入 : XtraForm
    {
        DataTable dt = null;
        List<cpclass> cps;
        public delegate void DoAction(List<cpclass> cps,int comboID);//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        public 号码导入()
        {
            InitializeComponent();
            
        }

        private void btne_file_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            openFileDialog1.ShowDialog();
            cps = new List<cpclass>();
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(openFileDialog1.FileName))
            {
                btne_file.Text = openFileDialog1.FileName;
                dt = Comm.getSheets(openFileDialog1.FileName,checkEdit1.Checked);
                if (dt!=null)
                {
                    lue_sheet.Properties.DataSource = dt;
                    lue_sheet.Properties.DisplayMember = "TABLE_NAME";
                    lue_sheet.Properties.ValueMember = "TABLE_NAME";
                    lue_sheet.EditValue = dt.Rows[0][2];
                }

            }
        }

        private void lue_sheet_EditValueChanged(object sender, EventArgs e)
        {
            gridControl1.DataSource = Comm.ReadExcelToTable(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
            lue_c1.Properties.DataSource = Comm.getSheetsCloum(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
            lue_C2.Properties.DataSource = Comm.getSheetsCloum(btne_file.Text, lue_sheet.Text, checkEdit1.Checked);
        }

        private void btne_file_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (dxValidationProvider1.Validate())
            {
                DataTable d = gridControl1.DataSource as DataTable;
                for (int i = 0; i < d.Rows.Count; i++)
                {
                    cpclass b = new cpclass();
                    //b.cid = d.Rows[i][lue_c1.Text].ToString();
                    b.phoneno = d.Rows[i][lue_C2.Text].ToString();
                    if (b.phoneno.Trim() != "")
                    {
                        cps.Add(b);
                    }
                }
                FatherRefresh(cps,int.Parse(lookUpEdit1.EditValue.ToString()));
                this.Close();
            }
        }

        private void 号码导入_Load(object sender, EventArgs e)
        {
            lookUpEdit1.Properties.DataSource = my.bw.Combo_Get("", my.ACID);
        }


    }
}